package com.example.thirdannotation.y2024.condition;

import com.example.thirdannotation.y2024.bean.Yellow;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
    /**
     *
     * @param annotationMetadata: 当前类的注解信息
     * @param registry: BeanDefinition 注册类, 调用 registerBeanDefinitions 手动注册进来
     */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry registry) {
        boolean redBool = registry.containsBeanDefinition("com.example.thirdannotation.y2024.bean.Red");
        boolean blueBool = registry.containsBeanDefinition("com.example.thirdannotation.y2024.bean.Blue");
        if (redBool && blueBool) {
            RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(Yellow.class);
            registry.registerBeanDefinition("yellow",rootBeanDefinition);
        }

    }
}
